﻿using System;
using System.Web;
using ToolsModel;

namespace BackendLogic.BaseLogic
{
    /// <summary>
    /// 用户session处理
    /// </summary>
    public class UserSession
    {
        /// <summary>
        /// 获取当前后台登录者信息
        /// </summary>
        /// <returns>处理结果</returns>
        public static AdminTicket GetLoginUser()
        {
            #region 获取当前登录者信息
            AdminTicket result = null;
            try
            {
                if (HttpContext.Current.Session["User"] != null)
                {
                    result = HttpContext.Current.Session["User"] as AdminTicket;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
            #endregion
        }

        /// <summary>
        /// 增加session
        /// </summary>
        /// <param name="clientInfo"></param>
        public static void AddLoginUser(AdminTicket clientInfo)
        {
            HttpContext rq = HttpContext.Current;
            rq.Session["user"] = clientInfo;
        }

        /// <summary>
        /// 删除session
        /// </summary>
        public static void RemoveLoginUser()
        {
            HttpContext rq = HttpContext.Current;
            rq.Session["user"] = null;
        }

    }
}
